/*
 * PapelDao.java
 *
 * Created on 19 de Setembro de 2007, 11:34
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.sgpa.persistencia;

import br.com.sgpa.dominio.Papel;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author agalrmo
 */
public class PapelDao extends Dao<Papel,Long> {
    
    /** Creates a new instance of PapelDao */
    public PapelDao(EntityManager em,Class classe) {
        super(em,classe);   
    }
    
    public List<Papel> listar(String descricao)
    {
        Query q = super.gerenciadorDeEntidades.createQuery("SELECT p FROM Papel p WHERE p.descricao LIKE ?1");
        q.setParameter(1,"%" + descricao + "%");
        return  (List<Papel>) q.getResultList ();
    }
    
    public Papel consultarPorDescricao(String descricao)
    {
        Query q = super.gerenciadorDeEntidades.createQuery("SELECT p FROM Papel p WHERE p.descricao = ?1");
        q.setParameter(1,descricao);
        return  (Papel) q.getSingleResult();
    }
}
